
package ch.hearc.coursJava.kitBase.de.wrapper;

import java.util.HashSet;
import java.util.Set;

import ch.hearc.coursJava.kitBase.tools.AleaTools;

public class LancerDe implements Runnable
	{

	/*------------------------------------------------------------------*\
	|*							Constructeurs							*|
	\*------------------------------------------------------------------*/

	public LancerDe(int nbFaces, int nbLancerTotal, int nbPasses)
		{
		this.nbFaces = nbFaces;
		this.nbLancerTotal = nbLancerTotal;
		this.nbPasses = nbPasses;
		//output
		this.nbLancersNecessaires=-1;
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Public							*|
	\*------------------------------------------------------------------*/

	@Override
	public void run()
		{
		Set<Integer> setValeurs = new HashSet<Integer>(nbFaces);

		for(int i = 0; i < nbPasses; i++)
			{
			setValeurs.clear();

			while(setValeurs.size() < nbFaces)
				{
				int val = AleaTools.lancer(nbFaces);
				setValeurs.add(val);
				nbLancerTotal++;
				}
			}

		nbLancersNecessaires = (int)Math.ceil(nbLancerTotal / (double)nbPasses);
		}

	@Override
	public String toString()
		{
		StringBuilder builder = new StringBuilder();
		builder.append("LancerDe [nbFaces=");
		builder.append(this.nbFaces);
		builder.append(", nbLancerTotal=");
		builder.append(this.nbLancerTotal);
		builder.append(", nbPasses=");
		builder.append(this.nbPasses);
		builder.append("]");
		return builder.toString();
		}

	/*------------------------------*\
	|*				Get				*|
	\*------------------------------*/

	public int getNbLancersNecessaires()
		{
		return this.nbLancersNecessaires;
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/

	/*------------------------------------------------------------------*\
	|*							Attributs Private						*|
	\*------------------------------------------------------------------*/

	//inputs
	private int nbFaces;
	private int nbLancerTotal;
	private int nbPasses;

	//output
	private int nbLancersNecessaires;
	}
